package com.jiazhong.servlet.controller;

import com.alibaba.fastjson.JSONArray;
import com.jiazhong.servlet.service.S10UserService;
import com.jiazhong.servlet.service.impl.S10UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/user")
public class S10UserController extends BaseController {

    private S10UserService service = new S10UserServiceImpl();

    public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        JsonResult result = service.login(username, password, request.getSession());
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println(JSONArray.toJSONString(result));
    }

}
